package com.mall507.fivepeaks.widget.lock;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;

import com.mall507.fivepeaks.R;

public class StarLockView extends ViewGroup implements OnClickListener {

	public static final int MSG_LAUNCH_HOME = 0;
	public static final int MSG_LAUNCH_DIAL = 1;
	public static final int MSG_LAUNCH_SMS = 2;
	public static final int MSG_LAUNCH_CAMERA = 3;
	private Context mContext;
	private Handler mainHandler = null;
	private float mx;
	private float my;

	private int mWidth, mHight;
	private int mScreenHalfWidth;
	private int mAlphaViewWidth, mAlphaViewHeight;
	private int mCenterViewWidth, mCenterViewHeight;
	private int mCenterViewTop, mCenterViewBottom;
	private int mAlphaViewTop, mAlphaViewBottom;
	private int mSmsViewHalfWidth, mSmsViewHalfHeight;
	private int mDialViewHalfWidth, mDialViewHalfHeight;
	private int mCameraViewHalfWidth, mHalfCameraViewHeight;
	private int mUnlockViewHalfWidth, mUnlockViewHalfHeight;
	private int mLightViewHalfWidth, mLightViewHalfHeight;
	private int tv_rightViewHalfWidth, tv_rightViewHalfHeight;
	private int tv_leftViewHalfWidth, tv_leftViewHalfHeight;
	
	private String left_type;

	private ImageView  mSmsView,mDialView,mCameraView, mUnLockView;
	private TextView tv_right, tv_left;
	private ImageView mCenterView, mAlphaView;
	private ImageView mSmsLightView, mUnLockLightView, mCameraLightView,mDialLightView;
	private Rect smsRect, dialRect, cameraRect, unlockRect;
	private Rect mCenterViewRect;

	private AlphaAnimation alpha;
	private boolean mTracking = false;

	public StarLockView(Context context, AttributeSet attrs) {
		super(context, attrs, 0);
		mContext = context;
		initViews(context);
		onAnimationStart();
	}

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		if (changed) {
			mWidth = r;
			mHight = b;
		    //mHalfWidth >> 1为向右位移1位，相当于mHalfWidth / 2。采用位移的原因是计算效率比较高。
			mScreenHalfWidth = mWidth >> 1;

			getViewMeasure();
			mCenterViewTop = 4 * mHight / 7 - (mCenterViewHeight >> 1);
			mCenterViewBottom = 4 * mHight / 7 + (mCenterViewHeight >> 1);
			mAlphaViewTop = 4 * mHight / 7 - (mAlphaViewHeight >> 1);
			mAlphaViewBottom = 4 * mHight / 7 + (mAlphaViewHeight >> 1);

			setChildViewLayout();
			setActivatedViewLayout();
			getChildViewRect();

			mCenterViewRect = new Rect(mWidth / 2 - mAlphaViewWidth / 2,mAlphaViewTop, mWidth / 2 + mAlphaViewWidth / 2,mAlphaViewBottom);

		}
	}

	//获取各个图标的宽、高
	private void getViewMeasure() {
		mAlphaView.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		mAlphaViewWidth = mAlphaView.getMeasuredWidth();
		mAlphaViewHeight = mAlphaView.getMeasuredHeight();

		mCenterView.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		mCenterViewWidth = mCenterView.getMeasuredWidth();
		mCenterViewHeight = mCenterView.getMeasuredHeight();

		mSmsView.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		mSmsViewHalfWidth = (mSmsView.getMeasuredWidth()) >> 1;
		mSmsViewHalfHeight = (mSmsView.getMeasuredHeight()) >> 1;

		tv_right.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		tv_rightViewHalfWidth = (tv_right.getMeasuredWidth()) >> 1;
		tv_rightViewHalfHeight = (tv_right.getMeasuredHeight()) >> 1;
		
		tv_left.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		tv_leftViewHalfWidth = (tv_left.getMeasuredWidth()) >> 1;
		tv_leftViewHalfHeight = (tv_left.getMeasuredHeight()) >> 1;

		mDialView.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		mDialViewHalfWidth = (mDialView.getMeasuredWidth()) >> 1;
		mDialViewHalfHeight = (mDialView.getMeasuredHeight()) >> 1;

		mCameraView.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		mCameraViewHalfWidth = (mCameraView.getMeasuredWidth()) >> 1;
		mHalfCameraViewHeight = (mCameraView.getMeasuredHeight()) >> 1;

		mUnLockView.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		mUnlockViewHalfWidth = (mUnLockView.getMeasuredWidth()) >> 1;
		mUnlockViewHalfHeight = (mUnLockView.getMeasuredHeight()) >> 1;

		mSmsLightView.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		mLightViewHalfWidth = (mSmsLightView.getMeasuredWidth()) >> 1;
		mLightViewHalfHeight = (mSmsLightView.getMeasuredHeight()) >> 1;

	}

	//设置高亮图标的布局
	private void setActivatedViewLayout() {
		mUnLockLightView.layout(mScreenHalfWidth - mLightViewHalfWidth - 5,
						       (mCenterViewTop + 2 * mCenterViewHeight)- mLightViewHalfHeight, mScreenHalfWidth+ mLightViewHalfWidth - 5,
						       (mCenterViewBottom + mCenterViewHeight)+ mLightViewHalfHeight);
		
		mSmsLightView.layout((mScreenHalfWidth + 3 * mCenterViewWidth / 2) - 2* mLightViewHalfWidth, 
				             (mCenterViewTop + mCenterViewHeight / 2)- mLightViewHalfHeight,
				             (mScreenHalfWidth + 3 * mCenterViewWidth / 2) + 2* mLightViewHalfWidth,
				             (mAlphaViewBottom - mCenterViewHeight / 2)+ mLightViewHalfHeight);
		
		mDialLightView.layout((mScreenHalfWidth - 3 * mCenterViewWidth / 2)- mLightViewHalfWidth, 
				              (mCenterViewTop + mCenterViewHeight / 2)- mLightViewHalfHeight,
				              (mScreenHalfWidth - 3 * mCenterViewWidth / 2)+ mLightViewHalfWidth,
				              (mAlphaViewBottom - mCenterViewHeight / 2)+ mLightViewHalfHeight);
		
		mCameraLightView.layout(mScreenHalfWidth - mLightViewHalfWidth,
				               (mCenterViewTop - mCenterViewHeight) - mLightViewHalfHeight,
				                mScreenHalfWidth + mLightViewHalfWidth,
				               (mCenterViewBottom - 2 * mCenterViewHeight)+ mLightViewHalfHeight);
	}

	//设置各图标在FxLockView中的布局
	private void setChildViewLayout() {
		mAlphaView.layout(mScreenHalfWidth - mAlphaViewWidth / 2,mAlphaViewTop, mScreenHalfWidth + mAlphaViewWidth / 2,mAlphaViewBottom);

		mCenterView.layout(mScreenHalfWidth - mCenterViewWidth / 2,mCenterViewTop, mScreenHalfWidth + mCenterViewWidth / 2,mCenterViewBottom);

		mSmsView.layout((mScreenHalfWidth + 3 * mCenterViewWidth / 2) - mSmsViewHalfWidth, 
				        (mCenterViewTop + mCenterViewHeight / 2)- mSmsViewHalfHeight,
				        (mScreenHalfWidth + 3 * mCenterViewWidth / 2) + mSmsViewHalfWidth,
				        (mAlphaViewBottom - mCenterViewHeight / 2) + mSmsViewHalfHeight);

		tv_right.layout((mScreenHalfWidth + 3 * mCenterViewWidth / 2)- tv_rightViewHalfWidth,
				        (mCenterViewTop + mCenterViewHeight / 2)+ tv_rightViewHalfHeight+8,
				        (mScreenHalfWidth + 3 * mCenterViewWidth / 2)+ tv_rightViewHalfWidth,
				        (mAlphaViewBottom - mCenterViewHeight / 2)+ tv_rightViewHalfHeight * 3+8);
		
		tv_left.layout((mScreenHalfWidth - 3 * mCenterViewWidth / 2)- tv_leftViewHalfWidth,
				       (mCenterViewTop + mCenterViewHeight / 2)+ tv_leftViewHalfHeight+8,
				       (mScreenHalfWidth - 3 * mCenterViewWidth / 2)+ tv_leftViewHalfWidth,
				       (mAlphaViewBottom - mCenterViewHeight / 2)+ tv_leftViewHalfHeight * 3+8);

		mDialView.layout((mScreenHalfWidth - 3 * mCenterViewWidth / 2)- mDialViewHalfWidth, 
				         (mCenterViewTop + mCenterViewHeight / 2)- mDialViewHalfHeight,
				         (mScreenHalfWidth - 3 * mCenterViewWidth / 2)+ mDialViewHalfWidth,
				         (mAlphaViewBottom - mCenterViewHeight / 2)+ mDialViewHalfHeight);
		

		mCameraView.layout(mScreenHalfWidth - mCameraViewHalfWidth,
				          (mCenterViewTop - mCenterViewHeight) - mHalfCameraViewHeight,
				          mScreenHalfWidth + mCameraViewHalfWidth,
				          (mCenterViewBottom - 2 * mCenterViewHeight)+ mHalfCameraViewHeight);

		mUnLockView.layout(mScreenHalfWidth - mUnlockViewHalfWidth,
						  (mCenterViewTop + 2 * mCenterViewHeight)- mUnlockViewHalfHeight, mScreenHalfWidth+ mUnlockViewHalfWidth,
						  (mCenterViewBottom + mCenterViewHeight)+ mUnlockViewHalfHeight);

	}

	//创建各图标位置对应的Rect
	private void getChildViewRect() {
		smsRect = new Rect((mScreenHalfWidth + 3 * mCenterViewWidth / 2) - 2* mSmsViewHalfWidth, 
				           (mCenterViewTop + mCenterViewHeight / 2)- mSmsViewHalfHeight,
				           (mScreenHalfWidth + 3 * mCenterViewWidth / 2) + 2* mSmsViewHalfWidth,
				           (mAlphaViewBottom - mCenterViewHeight / 2) + mSmsViewHalfHeight);

		dialRect = new Rect((mScreenHalfWidth - 3 * mCenterViewWidth / 2)- mDialViewHalfWidth, 
				            (mCenterViewTop + mCenterViewHeight / 2)- mDialViewHalfHeight,
				            (mScreenHalfWidth - 3 * mCenterViewWidth / 2)+ mDialViewHalfWidth,
				            (mAlphaViewBottom - mCenterViewHeight / 2)+ mDialViewHalfHeight);

		cameraRect = new Rect(mScreenHalfWidth - mCameraViewHalfWidth,
				             (mCenterViewTop - mCenterViewHeight) - mHalfCameraViewHeight,
				              mScreenHalfWidth + mCameraViewHalfWidth,
				             (mCenterViewBottom - 2 * mCenterViewHeight)+ mHalfCameraViewHeight);

		unlockRect = new Rect(mScreenHalfWidth - mUnlockViewHalfWidth,
				             (mCenterViewTop + 2 * mCenterViewHeight)- mUnlockViewHalfHeight, 
				              mScreenHalfWidth+ mUnlockViewHalfWidth,
				             (mCenterViewBottom + mCenterViewHeight) + mUnlockViewHalfHeight);
	}

	//获取图标，将获取的图标添加入FxLockView，设置图标的可见性
	private void initViews(Context context) {
		mAlphaView = new ImageView(context);
		mAlphaView.setImageResource(R.mipmap.centure2);
		setViewsLayout(mAlphaView);
		mAlphaView.setVisibility(View.INVISIBLE);

		mCenterView = new ImageView(context);
		mCenterView.setImageResource(R.mipmap.centure1);
		setViewsLayout(mCenterView);
		mCenterView.setVisibility(View.VISIBLE);

		mSmsView = new ImageView(context);
		mSmsView.setImageResource(R.mipmap.ad_gold);
		setViewsLayout(mSmsView);
		mSmsView.setVisibility(View.VISIBLE);

		tv_right = new TextView(context);
		tv_right.setText("+00");
		setTextViewsLayout(tv_right);
		tv_right.setVisibility(View.VISIBLE);
		
		tv_left= new TextView(context);
		tv_left.setText("+00");
		setTextViewsLayout(tv_left);
		tv_left.setVisibility(View.VISIBLE);

		mDialView = new ImageView(context);
		mDialView.setImageResource(R.mipmap.ad_phone);
		setViewsLayout(mDialView);
		mDialView.setVisibility(View.VISIBLE);

		mCameraView = new ImageView(context);
		mCameraView.setImageResource(R.mipmap.ad_phone);
		setViewsLayout(mCameraView);
		mCameraView.setVisibility(View.GONE);

		mUnLockView = new ImageView(context);
		mUnLockView.setImageResource(R.mipmap.home);
		setViewsLayout(mUnLockView);
		mUnLockView.setVisibility(View.GONE);

		mSmsLightView = new ImageView(context);
		setLightDrawable(mSmsLightView);
		setViewsLayout(mSmsLightView);
		mSmsLightView.setVisibility(INVISIBLE);

		mUnLockLightView = new ImageView(context);
		setLightDrawable(mUnLockLightView);
		setViewsLayout(mUnLockLightView);
		mUnLockLightView.setVisibility(INVISIBLE);

		mCameraLightView = new ImageView(context);
		setLightDrawable(mCameraLightView);
		setViewsLayout(mCameraLightView);
		mCameraLightView.setVisibility(INVISIBLE);

		mDialLightView = new ImageView(context);
		setLightDrawable(mDialLightView);
		setViewsLayout(mDialLightView);
		mDialLightView.setVisibility(INVISIBLE);
	}

	private void setLightDrawable(ImageView img) {
		img.setImageResource(R.mipmap.light);
	}

	//设置获取图标的参数，并添加到FxLockView
	private void setViewsLayout(ImageView image) {
		image.setScaleType(ScaleType.CENTER);
		image.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		image.setPadding(20, 0, 20, 25);
		addView(image);
	}

	//设置获取图标的参数，并添加到FxLockView
	private void setTextViewsLayout(TextView tv) {
		tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		tv.setGravity(Gravity.CENTER);
		tv.setTextSize(13);
		tv.setTextColor(getResources().getColor(R.color.white));
		addView(tv);
	}

	//设置音乐播放控制按钮的点击触摸反馈背景
	private void setMusicButtonBackground(ImageView musicIcon) {
		musicIcon.setVisibility(View.INVISIBLE);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		final int action = ev.getAction();
		final float x = ev.getX();
		final float y = ev.getY();

		switch (action) {
		case MotionEvent.ACTION_DOWN:
			//手指点在中心图标范围区域内
			if (mCenterViewRect.contains((int) x, (int) y)) {
				mTracking = true;
				// stopViewAnimation();
				onAnimationEnd();
				mAlphaView.setVisibility(View.INVISIBLE);
				return true;
			}
			break;

		default:
			break;
		}
//		if (DBG) Log.d(TAG, "onInterceptTouchEvent()");
		//此处返回false，onClick事件才能监听的到
		return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		/*mTracking为true时，说明中心图标被点击移动
		 * 即只有在中心图标被点击移动的情况下，onTouchEvent
		 * 事件才会触发。
		 */
		if (mTracking) {
			final int action = event.getAction();
			final float nx = event.getX();
			final float ny = event.getY();

			switch (action) {
			case MotionEvent.ACTION_DOWN:
				// showMusicButtons();
				break;
			case MotionEvent.ACTION_MOVE:
				setTargetViewVisible(nx, ny);
				//中心图标移动
				handleMoveView(nx, ny);
				break;
			case MotionEvent.ACTION_UP:
				mTracking = false;
				doTriggerEvent(mx, my);
				resetMoveView();
				break;
			case MotionEvent.ACTION_CANCEL:
				mTracking = false;
				doTriggerEvent(mx, my);
				resetMoveView();
				break;
			}
		}
		return mTracking || super.onTouchEvent(event);
	}

	//平方和计算
	private float dist2(float dx, float dy) {
		return dx * dx + dy * dy;
	}

	@SuppressLint("NewApi")
	private void handleMoveView(float x, float y) {

		int mHalfCenterViewWidth = mCenterViewWidth >> 1;

		//Radius为中心图标移动的限定的圆范围区域半径
		int Radius = mCenterViewWidth + mHalfCenterViewWidth;

		/*若用户手指移动的点与中心点的距离长度大于Radius，则中心图标坐标位置限定在移动区域范围圆弧上。
		 * 一般是用户拖动中心图标，手指移动到限定圆范围区域外。
		 */
		if (Math.sqrt(dist2(x - mScreenHalfWidth, y - (mCenterView.getTop() + mCenterViewWidth / 2))) > Radius) {
			//原理为x1 / x = r1 / r
			x = (float) ((Radius / (Math.sqrt(dist2(x - mScreenHalfWidth, y- (mCenterView.getTop() + mHalfCenterViewWidth)))))* (x - mScreenHalfWidth) + mScreenHalfWidth);
			y = (float) ((Radius / (Math.sqrt(dist2(x - mScreenHalfWidth, y- (mCenterView.getTop() + mHalfCenterViewWidth)))))* (y - (mCenterView.getTop() + mHalfCenterViewWidth))+ mCenterView.getTop() + mHalfCenterViewWidth);
		}
		y = mCenterView.getTop() + mCenterViewHeight/2;
		mx = x;
		my = y;
		/*
		 * 图形的坐标是以左上角为基准的，
		 * 所以，为了使手指所在的坐标和图标的中心位置一致，
		 * 中心坐标要减去宽度和高度的一半。
		 */
		mCenterView.setX((int) x - mCenterView.getWidth() / 2);
		mCenterView.setY((int) y - mCenterView.getHeight() / 2);
		ShowLightView(x, y);
		invalidate();
	}

	//监听解锁、启动拨号、相机、短信应用
	private void doTriggerEvent(float a, float b) {
		if (smsRect.contains((int) a, (int) b)) {
			onAnimationEnd();
			setTargetViewInvisible(mSmsView);
			virbate();
			mainHandler.obtainMessage(MSG_LAUNCH_SMS).sendToTarget();
		} else 
		if (dialRect.contains((int) a, (int) b)) {
			onAnimationEnd();
			setTargetViewInvisible(mDialView);
			virbate();
			mainHandler.obtainMessage(MSG_LAUNCH_DIAL).sendToTarget();
		} else 
		if (cameraRect.contains((int) a, (int) b)) {
			onAnimationEnd();
			setTargetViewInvisible(mCameraView);
			virbate();
			mainHandler.obtainMessage(MSG_LAUNCH_CAMERA).sendToTarget();
		} else 
		if (unlockRect.contains((int) a, (int) b)) {
			onAnimationEnd();
			setTargetViewInvisible(mUnLockView);
			virbate();
			mainHandler.obtainMessage(MSG_LAUNCH_HOME).sendToTarget();
		}
	}

	//中心图标拖动到指定区域时显示高亮图标
	private void ShowLightView(float a, float b) {
		if (unlockRect.contains((int) a, (int) b)) {
			setLightVisible(mUnLockLightView);
		} else 
		if (smsRect.contains((int) a, (int) b)) {
			setLightVisible(mSmsLightView);
		} else 
		if (dialRect.contains((int) a, (int) b)) {
			setLightVisible(mDialLightView);
		} else 
		if (cameraRect.contains((int) a, (int) b)) {
			setLightVisible(mCameraLightView);
		}else{
			setLightInvisible();
		}
	}

	private void setLightVisible(ImageView view) {
		view.setVisibility(View.VISIBLE);
		mCenterView.setVisibility(View.INVISIBLE);
	}

	//隐藏高亮图标
	private void setLightInvisible() {
		final View mActivatedViews[] = { mUnLockLightView, mSmsLightView,mDialLightView, mCameraLightView };
		for (View view : mActivatedViews) {
			view.setVisibility(View.INVISIBLE);
		}
		mCenterView.setVisibility(View.VISIBLE);
	}

	private void setTargetViewInvisible(ImageView img) {
		img.setVisibility(View.INVISIBLE);
	}

	private void setTargetViewVisible(float x, float y) {
		if (Math.sqrt(dist2(x - mScreenHalfWidth, y- (mCenterView.getTop() + mCenterViewWidth / 2))) > mAlphaViewHeight / 4) {
			return;
		}
	}

	private void setTargetViewVisible() {
		final View mTargetViews[] = { mSmsView, mDialView, mUnLockView,mCameraView };
		for (View view : mTargetViews) {
			view.setVisibility(View.VISIBLE);
		}
	}

	//重置中心图标，回到原位置
	@SuppressLint("NewApi")
	private void resetMoveView() {
		mCenterView.setX(mWidth / 2 - mCenterViewWidth / 2);
		mCenterView.setY((mCenterView.getTop() + mCenterViewHeight / 2)- mCenterViewHeight / 2);
		onAnimationStart();
		invalidate();
	}

	public void setMainHandler(Handler handler) {
		mainHandler = handler;
	}

	//解锁时震动
	private void virbate() {
		Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
		vibrator.vibrate(200);
	}

	//停止中心图标动画
	@Override
	protected void onAnimationEnd() {
		super.onAnimationEnd();
		if (alpha != null) {
			alpha = null;
		}
		mAlphaView.setAnimation(null);
	}

	//显示中心图标动画
	@Override
	protected void onAnimationStart() {
		super.onAnimationStart();
		mAlphaView.setVisibility(View.VISIBLE);

		if (alpha == null) {
			alpha = new AlphaAnimation(0.0f, 1.0f);
			alpha.setDuration(1000);
		}
		alpha.setRepeatCount(Animation.INFINITE);
		mAlphaView.startAnimation(alpha);
	}

	@Override
	public void onClick(View arg0) {
	}
	//设置左边数字
	public void setTv_left(String text,boolean show){
		tv_left.setText(text);
		tv_left.setLayoutParams(new LayoutParams(200, 100));
		if(show){
			tv_left.setVisibility(View.VISIBLE);
		}else{
			tv_left.setVisibility(View.GONE);
		}
	}
	//设置右边数字
	public void setTv_right(String text,boolean show){
		tv_right.setText(text);
		tv_right.setLayoutParams(new LayoutParams(200, 100));
		if(show){
			tv_right.setVisibility(View.VISIBLE);
		}else{
			tv_right.setVisibility(View.GONE);
		}
	}
	public TextView getTv_right(){
		return tv_right;
	}
	public TextView getTv_left(){
		return tv_left;
	}
	//设置左边图标
	public void setLeftType(String left){
		this.left_type=left;
		if("LT_1".equals(left)){
			mDialView.setImageResource(R.mipmap.ad_phone);
		}else 
		if("LT_2".equals(left)){
			mDialView.setImageResource(R.mipmap.ad_web);
		}else 
		if("LT_3".equals(left)){
			mDialView.setImageResource(R.mipmap.ad_down);
		}else 
		if("LT_4".equals(left)){
			mDialView.setImageResource(R.mipmap.ad_weixin);
		}else 
		if("LT_6".equals(left)){
			mDialView.setImageResource(R.mipmap.ad_shop);
		}else {
			mDialView.setImageResource(R.mipmap.ad_close);
//			mDialView.setBackgroundResource(R.mipmap.ad_icon_bg);
		}
		
	}
	public String getLeftType(){
		return left_type;
	}

}
